/**
 * 
 */
package com.sign.signsystem;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.location.LocationClientOption.LocationMode;
import com.biz.service.AttendanceService;
import com.core.entity.Location;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

/**
 * @author Bosto
 *
 */
public class StartAttendentActivity extends HandlerActivity{
	public LocationClient mLocationClient = null;
	Button startButton;
	Spinner spiner;
	TextView latitude,longitude,address;
	LocationApplication application = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.attend_lesson_layout);
		application = (LocationApplication) getApplication();
		mLocationClient = application.mLocationClient;
		spiner = (Spinner) findViewById(R.id.lesson_spinner);
		latitude = (TextView) findViewById(R.id.latitude_textview);
		longitude = (TextView) findViewById(R.id.longitude_textview);
		address = (TextView) findViewById(R.id.address_text);
		startButton = (Button) findViewById(R.id.begin_attendent_btn);
		startButton.setOnClickListener(this);
		startLocation();
	}
	
	
	
	
	protected void startLocation() {
		mLocationClient.registerLocationListener(new BDLocationListener(){
			@Override
			public void onReceiveLocation(BDLocation arg0) {
				ArrayAdapter adapter = new ArrayAdapter(StartAttendentActivity.this,
						R.layout.list_item_attendance, R.id.attendance_item,
						new AttendanceService().getTestSpinDropDown(application.getUserEntity()));
				spiner.setAdapter(adapter);
				latitude.setText(String.valueOf(arg0.getLatitude()));
				longitude.setText(String.valueOf(arg0.getLongitude()));
				address.setText(arg0.getAddrStr());
			}
			
		});
		InitLocation();
		mLocationClient.start();
	}




	private void InitLocation() {
		LocationClientOption option = new LocationClientOption();
		option.setLocationMode(LocationMode.Hight_Accuracy);// 设置定位模式
		option.setCoorType("bd09ll");// 返回的定位结果是百度经纬度,默认值gcj02
		option.setScanSpan(5000);// 设置发起定位请求的间隔时间为5000ms
		option.setIsNeedAddress(true);// 返回的定位结果包含地址信息
		option.setNeedDeviceDirect(true);// 返回的定位结果包含手机机头的方向
		mLocationClient.setLocOption(option);
	}

	@Override
	public void onStop() {
		mLocationClient.stop();
		super.onStop();
	}




	@Override
	public void onClick(View paramView) {
		this.finish();
	}




	@Override
	void hanldeMessage(Message msg) {
		
	}
	
}
